package com.mycoupon.mycouponframework.exception;

import com.mycoupon.mycouponframework.errorcode.BaseErrorCode;
import com.mycoupon.mycouponframework.errorcode.IErrorCode;

import java.util.Optional;

/**
 * @projectName: MyCoupon
 * @package: com.mycoupon.mycouponframework.exception
 * @className: ServiceException
 * @author: thinkBook
 * @description: 服务端异常，请求运行过程中出现的不符合业务预期的异常
 * @date: 2025/4/4 22:28
 * @version: 1.0
 */
public class ServiceException extends AbstractException{

    public ServiceException(String message) {
        this(message, null, BaseErrorCode.SERVICE_ERROR);
    }

    public ServiceException(IErrorCode errorCode) {
        this(null, errorCode);
    }

    public ServiceException(String message, IErrorCode errorCode) {
        this(message, null, errorCode);
    }

    public ServiceException(String message, Throwable throwable, IErrorCode errorCode) {
        super(Optional.ofNullable(message).orElse(errorCode.message()), throwable, errorCode);
    }

    @Override
    public String toString() {
        return "ServiceException{" +
                "code='" + errorCode + "'," +
                "message='" + errorMessage + "'" +
                '}';
    }
}
